<template>
  <el-dialog @close="shdkbjdCancel('shdkbjdRuleForm')" :close-on-click-modal="false" title="审核对客报价单"
    :visible.sync="shdkbjdVisible" width="600px">
    <div class="scroll-view">
      <el-descriptions :column="2" border>
        <el-descriptions-item label="报价金额" v-if="fieldShowFunc('quotation_amount')">{{dkData.old_amount}}</el-descriptions-item>
        <el-descriptions-item label="预计签约金额" v-if="fieldShowFunc('bj_new_amount')">{{dkData.new_amount}}</el-descriptions-item>
        <el-descriptions-item label="优惠金额" v-if="fieldShowFunc('bj_discount_amount')">{{dkData.discount_amount}}</el-descriptions-item>
        <el-descriptions-item label="备注" v-if="dkData.remark">{{dkData.remark}}</el-descriptions-item>
      </el-descriptions>
      <el-form :model="shdkbjdRuleForm" :rules="shdkbjdRules" ref="shdkbjdRuleForm" label-position="top">
        <el-form-item label="" prop="reviewPassed">
          <el-radio-group v-model="shdkbjdRuleForm.reviewPassed" size="small">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input :rows="4" class="input-box" v-model="shdkbjdRuleForm.remark" type="textarea"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer">
      <el-button @click="shdkbjdCancel('shdkbjdRuleForm')">关闭</el-button>
      <el-button type="primary" @click="shdkbjdSubmit('shdkbjdRuleForm')" :disabled="diaLoading" :loading="diaLoading">确
        定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import projectApi from "@/api/projectApi";
import companyApi from "@/api/companyApi";
import adminApi from "@/api/adminApi";
import { getUserInfo } from "@/utils/auth";
import foremanApi from "@/api/foremanApi";

export default {
  name: "",
  props: {
    addDialogVisible: {
      type: Boolean,
      default: false,
      required: false,
    },
    project_id: {
      required: false,
    },
    dkData: {
      required: false
    },
    fieldList:{
      required: false,
    }
  },
  data() {
    return {
      shdkbjdVisible: false,
      shdkbjdRuleForm: {
        review_id: "",
        remark: "",
        reviewPassed: 1,
      },
      shdkbjdRules: {},
      diaLoading: false,
    };
  },
  watch: {
    addDialogVisible(val1, val2) {
      this.shdkbjdVisible = this.addDialogVisible;
    },
  },
  computed: {},
  mounted() { },
  methods: {
    // 判断是否显示
    fieldShowFunc(field) {
      let fieldList = this.fieldList;
      return fieldList[field] == undefined ? true : fieldList[field];
    },
    // 审核对客报价单
    shdkbjdCancel(formName) {
      this.shdkbjdRuleForm = {
        review_id: "",
        remark: "",
        reviewPassed: 1,
      };
      this.$nextTick(() => {
        this.$refs[formName].clearValidate();
        this.$emit("onClose", true);
      });
    },
    shdkbjdSubmit(formName) {
      let shdkbjdRuleForm = this.shdkbjdRuleForm;
      console.log(shdkbjdRuleForm, "审核对客报价单参数");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.diaLoading = true;
          if (shdkbjdRuleForm.reviewPassed == 1) {
            // 通过
            projectApi
              .discountReviewPassed({
                project_id: this.project_id,
                review_id: "",
                remark: shdkbjdRuleForm.remark,
                type: 1
              })

              .then((res) => {
                console.log(res, "审核对客报价单");
                this.diaLoading = false;
                if (res.code == 200) {
                  this.$emit('onSuccess', true);
                }
                this.$message({
                  type: res.code == 200 ? "success" : "warning",
                  message: res.code == 200 ? "处理成功" : res.message,
                });
              })
              .catch((err) => {
                this.diaLoading = false;
                this.$message({
                  type: "warning",
                  message: err.message,
                });
              });
            return;
          }
          // 拒绝
          projectApi
            .discountReviewRejected({
              project_id: this.project_id,
              review_id: "",
              remark: shdkbjdRuleForm.remark,
              type: 1
            })
            .then((res) => {
              console.log(res, "审核对客报价单");
              this.diaLoading = false;
              if (res.code == 200) {
                this.$emit("onSuccess", true);
              }
              this.$message({
                type: res.code == 200 ? "success" : "warning",
                message: res.code == 200 ? "处理成功" : res.message,
              });
            })
            .catch((err) => {
              this.diaLoading = false;
              this.$message({
                type: "warning",
                message: err.message,
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>